// WorkHistory.cs
// Facebook/Framework/Service
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace Facebook.Service {

    /// <summary>
    /// Represents a Facebook work history entry on the user's profile.
    /// </summary>
    public sealed class WorkHistory : FacebookEntity {

        private bool _locationTransformed;

        internal WorkHistory(Hashtable workHistoryState)
            : base(workHistoryState) {
        }

        /// <summary>
        /// The location associated with the workplace.
        /// </summary>
        public Location Location {
            get {
                if (_locationTransformed == false) {
                    return TransformLocation();
                }
                return (Location)this["location"];
            }
        }

        /// <summary>
        /// The end date associated with the workplace if any.
        /// </summary>
        public string EndDate {
            get {
                return GetState<string>("end_date") ?? String.Empty;
            }
        }

        /// <summary>
        /// The name of the company associated with the workplace.
        /// </summary>
        public string Name {
            get {
                return GetState<string>("company_name") ?? String.Empty;
            }
        }

        /// <summary>
        /// The description of the work.
        /// </summary>
        public string Description {
            get {
                return GetState<string>("description") ?? String.Empty;
            }
        }

        /// <summary>
        /// The position held by the user at the workplace.
        /// </summary>
        public string Position {
            get {
                return GetState<string>("position") ?? String.Empty;
            }
        }

        /// <summary>
        /// The start date associated with the workplace if any.
        /// </summary>
        public string StartDate {
            get {
                return GetState<string>("start_date") ?? String.Empty;
            }
        }

        private Location TransformLocation() {
            Debug.Assert(_locationTransformed == false);

            Hashtable locationState = (Hashtable)this["location"];
            Location location = new Location(locationState);

            this["location"] = location;
            _locationTransformed = true;

            return location;
        }
    }
}
